using UnityEngine;

namespace EpicToonFX
{
    // [Assembly-CSharp.dll].EpicToonFX.ETFXMouseOrbit
    public class ETFXMouseOrbit : MonoBehaviour
    {
        // Fields
        public UnityEngine.Transform target;
        public float distance;
        public float xSpeed;
        public float ySpeed;
        public float yMinLimit;
        public float yMaxLimit;
        public float distanceMin;
        public float distanceMax;
        public float smoothTime;
        private float rotationYAxis;
        private float rotationXAxis;
        private float velocityX;
        private float velocityY;
        
        // Methods
        private void Start()
        {
            UnityEngine.Vector3 val_2 = this.transform.eulerAngles;
            this.rotationYAxis = val_2.y;
            this.rotationXAxis = val_2.x;
            if((UnityEngine.Object.op_Implicit(exists:  this.GetComponent<System.Object>())) == false)
            {
                    return;
            }
            
            this.GetComponent<System.Object>().freezeRotation = true;
        }
        private void LateUpdate()
        {
            UnityEngine.Transform val_25;
            float val_26;
            float val_28;
            val_25 = this.target;
            if((UnityEngine.Object.op_Implicit(exists:  val_25)) == false)
            {
                    return;
            }
            
            val_25 = 27508056;
            if((UnityEngine.Input.GetMouseButton(button:  1)) != false)
            {
                    float val_3 = UnityEngine.Input.GetAxis(axisName:  -1610605295);
                val_3 = this.xSpeed * val_3;
                val_3 = val_3 * this.distance;
                val_3 = val_3 * 0.02f;
                val_3 = this.velocityX + val_3;
                this.velocityX = val_3;
                float val_4 = UnityEngine.Input.GetAxis(axisName:  -1610605293);
                val_4 = this.ySpeed * val_4;
                val_4 = val_4 * 0.02f;
                val_26 = this.velocityY + val_4;
                this.velocityY = val_26;
            }
            else
            {
                    val_26 = this.velocityY;
            }
            
            float val_26 = this.rotationXAxis;
            float val_25 = this.velocityX;
            val_25 = this.rotationYAxis + val_25;
            float val_27 = -360f;
            val_26 = val_26 - val_26;
            val_26 = val_26 + 360f;
            val_26 = (val_26 < 0) ? (val_26) : (val_26);
            val_27 = val_26 + val_27;
            val_26 = (val_26 > 360f) ? (val_27) : (val_26);
            val_27 = (val_26 > this.yMaxLimit) ? this.yMaxLimit : (val_26);
            val_26 = (val_26 >= 0) ? (val_27) : this.yMinLimit;
            this.rotationYAxis = val_25;
            this.rotationXAxis = val_26;
            val_26 = val_26 * 0.01745329f;
            val_25 = val_25 * 0.01745329f;
            UnityEngine.Quaternion val_5 = UnityEngine.Quaternion.Internal_FromEulerRad(euler:  new UnityEngine.Vector3() {x = val_26, y = val_25, z = 0f});
            float val_6 = UnityEngine.Input.GetAxis(axisName:  -1610605297);
            val_6 = val_6 * (-5f);
            val_6 = this.distance + val_6;
            val_6 = (val_6 >= 0) ? ((val_6 > this.distanceMax) ? this.distanceMax : (val_6)) : this.distanceMin;
            this.distance = val_6;
            UnityEngine.Vector3 val_8 = this.target.position;
            UnityEngine.Vector3 val_10 = this.transform.position;
            val_28 = this.distance;
            if((UnityEngine.Physics.Linecast(start:  new UnityEngine.Vector3() {x = val_8.x, y = val_8.y, z = val_8.z}, end:  new UnityEngine.Vector3() {x = val_10.x, y = val_10.y, z = val_10.z}, hitInfo:  new UnityEngine.RaycastHit() {m_Point = new UnityEngine.Vector3() {x = 0f, y = 0f, z = 0f}, m_Normal = new UnityEngine.Vector3() {x = 0f, y = 0f, z = 0f}, m_Distance = 0f, m_UV = new UnityEngine.Vector2() {x = 0f, y = 0f}})) != false)
            {
                    val_28 = val_28 - 0.distance;
                this.distance = val_28;
            }
            
            UnityEngine.Vector3 val_13 = UnityEngine.Quaternion.op_Multiply(rotation:  new UnityEngine.Quaternion() {x = val_5.x, y = val_5.y, z = val_5.z, w = val_5.w}, point:  new UnityEngine.Vector3() {x = 0f, y = 0f, z = -val_28});
            UnityEngine.Vector3 val_14 = this.target.position;
            this.transform.rotation = new UnityEngine.Quaternion() {x = val_5.x, y = val_5.y, z = val_5.z, w = val_5.w};
            float val_28 = val_13.x;
            val_28 = val_28 + val_14.x;
            this.transform.position = new UnityEngine.Vector3() {x = val_28, y = val_13.y + val_14.y, z = val_13.z + val_14.z};
            float val_19 = UnityEngine.Time.deltaTime;
            val_19 = val_19 * this.smoothTime;
            float val_21 = (val_19 >= 0) ? this.smoothTime : 0f;
            val_21 = (0f - this.velocityX) * val_21;
            val_21 = this.velocityX + val_21;
            this.velocityX = val_21;
            float val_22 = UnityEngine.Time.deltaTime;
            val_22 = val_22 * this.smoothTime;
            float val_23 = (val_22 >= 0) ? this.smoothTime : 0f;
            val_23 = (0f - this.velocityY) * val_23;
            val_23 = this.velocityY + val_23;
            this.velocityY = val_23;
        }
        public static float ClampAngle(float angle, float min, float max)
        {
            float val_1 = angle + 360f;
            angle = (angle < 0) ? (val_1) : angle;
            val_1 = angle + (-360f);
            angle = (angle > 360f) ? (val_1) : (angle);
            angle = (angle >= 0) ? ((angle > max) ? max : (angle)) : min;
            return (float)angle;
        }
        public ETFXMouseOrbit()
        {
            this.distance = ;
            this.xSpeed = ;
            this.ySpeed = 120f;
            this.yMinLimit = -20f;
            this.yMaxLimit = ;
            this.distanceMin = ;
            this.distanceMax = 15f;
            this.smoothTime = 2f;
        }
    
    }

}
